package com.example.lzy.listviewsample.Spinner;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.example.lzy.listviewsample.R;

public class SpinnerActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

    private Spinner spinner1 = null;
    private Spinner spinner2 = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.spinner_layout);

       spinner1 = (Spinner) findViewById(R.id.spin_one);
        spinner2 = (Spinner) findViewById(R.id.spin_two);

        String[] strings = {"安卓开发","安卓开发89","安卓开发54","安卓开发20"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,strings);

        spinner2.setAdapter(adapter);

        spinner1.setOnItemSelectedListener(this);
        spinner2.setOnItemSelectedListener(this);


    }


    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

        String s = adapterView.getItemAtPosition(i).toString();
        switch (adapterView.getId()){
            case R.id.spin_one:
                Toast.makeText(this, "专业"+s, Toast.LENGTH_SHORT).show();
                break;
            case R.id.spin_two:
                Toast.makeText(this, "书籍"+s, Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }
}
